package GUI;

import java.awt.Color;
import java.awt.Graphics;
import java.io.IOException;

import javax.swing.AbstractButton;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;

import Messages.MessageGetAllMenues;
import Messages.MessageGetAllMenuesReply;
import java.awt.Font;

/**
 * this class creates JButton for the class PFScheem_All_Tables
 * the button is a table 
 * the button includes data about a table:
 * 1.name of the waiter of this table
 * 2.counter of minutes that passed from the time of opening table
 * 
 * @author igor
 *
 */
public class ButtonForTable extends JButton {
	
	private String tableNo;
	private String status="free";
	private String nameOfOfficiant;
	private String minutsFromOpen;
	private String minutsFromLastServing;
	private String numOfPersons;
	private boolean isUpgrated=true;
	private MainMenu mainMenu;	
	private JLabel nameLbl;
	private JLabel minutsOpenLbl;
	private JLabel minutsLastServLbl;
	private JLabel numOfPersonsLbl;
	
	
	/**
	 * Creates the button with number of a table
	 * 
	 * @param num - number of the table
	 * @param mm - Main class of data 
	 */
	public ButtonForTable (String num, MainMenu mm)
	{
		super(num);
		//setForeground(new Color(0, 0, 0));
		this.setFont(new Font("Tahoma", Font.BOLD, 25));
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		tableNo=num;
		mainMenu=mm;
		this.setVerticalTextPosition(AbstractButton.TOP);
		this.setHorizontalTextPosition(AbstractButton.CENTER);
		nameLbl=new JLabel();
		nameLbl.setFont(new Font("Tahoma", Font.BOLD, 14));
		minutsOpenLbl=new JLabel();
		minutsOpenLbl.setFont(new Font("Tahoma", Font.PLAIN, 13));
		minutsLastServLbl=new JLabel();
		minutsLastServLbl.setFont(new Font("Tahoma", Font.PLAIN, 13));
		numOfPersonsLbl=new JLabel();
		numOfPersonsLbl.setFont(new Font("Tahoma", Font.PLAIN, 13));
		this.add(nameLbl);
		this.add(minutsOpenLbl);
		this.add(minutsLastServLbl);
		this.add(numOfPersonsLbl);
		
		
	}
	
	/**
	 * sets status "free"  
	 * free table(button) for a new order
	 */
	public void setStatusFree()
	{
		status="free";
		repaint();
	}

	/**
	 * set status "ordered"
	 * 
	 */
	public void setStatusOrdered()
	{
		status="ordered";
		repaint();
	}
	
	/**
	 * 
	 * @return number of a table
	 */
	public String getTableNo() {
		return tableNo;
	}


	/**
	 * sets number of the table for the button
	 * @param tableNo - number of the table
	 */
	public void setTableNo(String tableNo) {
		this.tableNo = tableNo;
	}
	
	/**
	 * 
	 * @return name of the waiter who serves this table
	 */
	public String getNameOfOfficiant() {
		return nameOfOfficiant;
	}

/**
 * sets name of the waiter who serves this table
 * 
 * @param nameOfOfficiant- name of waiter
 */
	public void setNameOfOfficiant(String nameOfOfficiant) {
		this.nameOfOfficiant = nameOfOfficiant;
		nameLbl.setText("המלצר : "+nameOfOfficiant);
	}
	
	
	
	
	public void setNumOfPersons(int numOfPersons) {
		this.numOfPersons = Integer.toString(numOfPersons);
		numOfPersonsLbl.setText("מס' סועדים : "+this.numOfPersons);
	}
	
	
	

/**
 * 
 * @return the number of minutes that have passed since the table opening
 */
	public String getMinutsFromOpen() {
		return minutsFromOpen;
	}

/**
 * sets the number of minutes that have passed since the table opening
 * @param minutsFromOpen - minutes from opening table
 */
	public void setMinutsFromOpen(String minutsFromOpen) {
		this.minutsFromOpen = minutsFromOpen;
		minutsOpenLbl.setText("נפתח לפני : "+minutsFromOpen);
		
	}


	public String getMinutsFromLastServing() {
		return minutsFromLastServing;
	}


	public void setMinutsFromLastServing(String minutsFromLastServing) {
		this.minutsFromLastServing = minutsFromLastServing;
		minutsLastServLbl.setText("מנה אחרונה הוצאה לפני : "+minutsFromLastServing);
	}
	
	
	
	/**
	 * this method free the table 
	 */
	public void cleanButton()
	{
		this.setStatusFree();
		this.minutsOpenLbl.setText(null);
		this.nameLbl.setText(null);
	}
	
	
	
	
	/**
	 * paints the button with the chosen parameters
	 * 
	 * 
	 */
	public void paintComponent( Graphics g )
	{
		super.paintComponent(g);
		if (status=="free")
		{
			this.setBackground(Color.white);
		}
		
		if (status=="ordered")
		{
			if(Integer.parseInt(minutsFromOpen)<60)
				this.setBackground(Color.GREEN);
			else
				this.setBackground(new Color(255, 99, 71));
			
			if (isUpgrated)
			{
			
			}
		}
	}
}
